<?php
$c_nickname = $_SESSION['cname'];
$query = "select * from tbl_period";
$result = mysql_query($query);
 
$ct_query = "select tbl_companies.`c_nickname`,tbl_company_type.ct_id,tbl_company_type.ct_company from tbl_companies inner join tbl_company_type on tbl_companies.ct_id = tbl_company_type.ct_id where tbl_companies.`c_nickname`='$c_nickname'";
$ct_result = mysql_fetch_array(mysql_query($ct_query));
$type = $ct_result['ct_company'];

?>
<fieldset style="font-size:12px;">
<legend><h3>Billing Period Information</h3></legend>
<table cellpadding="2">
	<tr style="background-color:#0673C5;color:#FFFFFF;">
		<th>Start Date</th>
		<th>End Date</th>
		<th>p_split_trunk</th>
		<th>p_split_no_trunk</th>
		<th>Action</th>
	</tr>
	<? while($bill = mysql_fetch_array($result)){?>
	<tr style="background-color:#E6E9F2;">
		<td><?=$bill['p_start_date']?></td>
		<td><?=$bill['p_end_date']?></td>
		<td><?=$bill['p_split_trunk']?></td>
		<td><?=$bill['p_split_no_trunk']?></td>
		<?php
			$count = 1;
			for($i=1;$i<=7; $i++)
			{
				$day = date("w",strtotime(date("Y-m-d", strtotime($bill['p_end_date'])) . " +$i days"));
				if(!($day == 0 || $day == 6))
				{
					$count ++;
				}
				if($count >5)
				{
					$final= date("Y-m-d",strtotime(date("Y-m-d", strtotime($bill['p_end_date'])) . " +$i days"));
					break;
				}
			}
			if($type == 'DCSP'){
				$billid = $bill['p_id'];
				$billquery = "select * from tbl_dcsp_bb where p_id = '$billid'";
				$data = mysql_fetch_array(mysql_query($billquery));
				if($data['p_id'] != $bill['p_id']){
					if(strtotime(date("Y-m-d"))-strtotime($bill['p_end_date']) > 0){
						if(strtotime(date("Y-m-d"))-strtotime($final) < 0)
						{
							echo "<td><a href='index.php?page=billform&Id=".$bill['p_id']."' style='color:#FFFB00;'>Fill Form</a></td>";
						 }
						else{
							echo "<td>&nbsp;</td>";
						}
					}else{
							echo "<td><a href='index.php?page=billform&Id=".$bill['p_id']."'>Fill Form</a></td>";
					}
				}
				else{
					echo "<td><a href='index.php?page=billform&Id=".$bill['p_id']."'>Update Form</a></td>";
				}
			}else if($type == 'IXC'){
				$billid = $bill['p_id'];
				$billquery = "select * from tbl_ixc_bb where p_id = '$billid'";
				$data = mysql_fetch_array(mysql_query($billquery));
				if($data['p_id'] != $bill['p_id']){
					if(strtotime(date("Y-m-d"))-strtotime($bill['p_end_date']) > 0){
						if(strtotime(date("Y-m-d"))-strtotime($final) < 0)
						{
							echo "<td><a href='index.php?page=ixcform&Id=".$bill['p_id']."' style='color:#FFFB00;'>Fill Form</a></td>";
						 }
						else{
							echo "<td>&nbsp;</td>";
						}
					}else{
							echo "<td><a href='index.php?page=ixcform&Id=".$bill['p_id']."'>Fill Form</a></td>";
					}
				}
				else{
					echo "<td><a href='index.php?page=ixcform&Id=".$bill['p_id']."'>Update Form</a></td>";
				}
			}
		?>
	</tr>
	<?}?>
</table>
</fieldset>
<?
//					$count = 1;
//					for($i=1;$i<=7; $i++)
//					{
//					 $day = date("w",strtotime(date("Y-m-d", strtotime($bill['p_end_date'])) . " +$i days"));
//					if(!($day == 0 || $day == 6))
//					{
//						$count ++;
//					}
//					if($count >5)
//					{
//						echo $final= date("Y-m-d",strtotime(date("Y-m-d", strtotime($bill['p_end_date'])) . " +$i days"));
//						break;
//					}
//					}
//					if(strtotime(date("Y-m-d"))-strtotime($bill['p_end_date']) > 0){
//						
//						
//						if(strtotime(date("Y-m-d"))-strtotime($final) < 0)
//						{
//							echo "yellow(can fill the form)";
//						}
//						else
//						{
//							echo "cannot fill form";
//						}
//						
//						}
//					?>
